package com.example.controller;

import com.example.feign.RemoteStockFeignService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wangzhenjun
 * @date 2023/10/31 14:25
 */
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/order")
@RestController
public class OrderController {

    private final RemoteStockFeignService remoteStockFeignService;
    /**
     * 模拟下单流程
     * @param userId
     * @param productId
     * @return
     */
    @GetMapping("/createOrder")
    public String createOrder(@RequestParam("userId") Integer userId, @RequestParam("productId") Integer productId) {
        log.info("====>订单模块<========");
        // 调用库存服务进行库存扣减
        String stockResult = remoteStockFeignService.subtractStock(userId,productId,1);
        log.info("扣减库存结果：{}", stockResult);
        // 还有其他。。。。。

        return "下单成功！";
    }
}
